package com.quartet.modules.equipment.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.quartet.api.PageResult;
import com.quartet.modules.equipment.dao.TStockInfoDao;
import com.quartet.modules.equipment.dto.TStockInfoRequestDto;
import com.quartet.modules.equipment.dto.TStockInfoResponseDto;
import com.quartet.modules.equipment.entity.TStockInfo;
import com.quartet.modules.equipment.service.TStockInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 库存信息表(TStockInfo)表服务实现类
 *
 * @author makejava
 * @since 2021-05-04 16:51:20
 */
@Service("tStockInfoService")
public class TStockInfoServiceImpl extends ServiceImpl<TStockInfoDao, TStockInfo> implements TStockInfoService {

    @Autowired
    private TStockInfoDao tStockInfoDao;

    /**
     * 条件查询库存信息带分页
     * @param tStockInfoRequestDto
     * @return
     */
    @Override
    public PageResult selectStockByCondition(TStockInfoRequestDto tStockInfoRequestDto) {
        PageHelper.startPage(tStockInfoRequestDto.getCurrent(), tStockInfoRequestDto.getLimit());
        PageInfo pageInfo = new PageInfo(tStockInfoDao.selectStockByCondition(tStockInfoRequestDto));
        Long total = pageInfo.getTotal();
        List<TStockInfoResponseDto> list = pageInfo.getList();
        PageResult<TStockInfoResponseDto> pageResult = new PageResult<>();
        pageResult.setTotal(total);
        pageResult.setData(list);
        return pageResult;
    }
}
